package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_BANK_LIST)
public class GetBankList extends JTAsyGet<GetBankList.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public GetBankList(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {
        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        info.logourl = body.optString("pictureUrl");

        JSONArray bankList = body.optJSONArray("mapList");

        if (bankList != null) {

            for (int i = 0; i < bankList.length(); i++) {

                JSONObject object_item = bankList.optJSONObject(i);

                BankList bankItem = new BankList();

                bankItem.ID = object_item.optString("id");

                bankItem.NAME = object_item.optString("name");

                bankItem.PIC = object_item.optString("path");

                bankItem.LOGO = object_item.optString("logo");

                bankItem.DESCRIBE1 = object_item.optString("message1");

                bankItem.DESCRIBE2 = object_item.optString("message2");

                bankItem.DESCRIBE3 = object_item.optString("message3");

                info.bankLists.add(bankItem);

            }

        }

        return info;
    }

    public static class Info {

        public String msg;

        public String logourl;

        public List<BankList> bankLists = new ArrayList<>();

    }

    public static class BankList implements Serializable {

        public String ID, NAME, LOGO,PIC,DESCRIBE1,DESCRIBE2,DESCRIBE3;

    }
}
